﻿using System;
using System.Runtime.InteropServices;

//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define LOG(format, ...) printf(">> " format "\n", ##__VA_ARGS__)
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define NULL (void*)0
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define EM_PORT_API(rettype) rettype EMSCRIPTEN_KEEPALIVE
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define EM_PORT_API(rettype) rettype
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define rb_parent(r) ((struct rb_node *)((r)->rb_parent_color & ~3))
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define rb_color(r) ((r)->rb_parent_color & 1)
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define rb_is_red(r) (!rb_color(r))
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define rb_is_black(r) rb_color(r)
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define rb_set_red(r) do { (r)->rb_parent_color &= ~1; } while (0)
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define rb_set_black(r) do { (r)->rb_parent_color |= 1; } while (0)
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define RB_ROOT (struct rb_root) { NULL, }
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define rb_entry(ptr, type, member) container_of(ptr, type, member)
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define container_of(ptr, type, member) ({ const typeof( ((type *)0)->member ) *__mptr = (ptr); (type *)( (char *)__mptr - offsetof(type,member) );})
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define RB_EMPTY_ROOT(root) ((root)->rb_node == NULL)
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define RB_EMPTY_NODE(node) (rb_parent(node) == node)
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define RB_CLEAR_NODE(node) (rb_set_parent(node, node))
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define offsetof(type, field) ((size_t) & ((type *)0)->field)
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define countof(x) (sizeof(x) / sizeof((x)[0]))
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define ALIGN(x, align) (((x) + ((align)-1)) & ~((align)-1))
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define MAKERGB565(r, g, b) (uint16_t)(((uint32_t)(r >> 3) << 11) | ((uint32_t)(g >> 2) << 5) | ((uint32_t)(b >> 3)))
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define PIXEL565R(v) ((((uint32_t)v >> 11) << 3) & 0xff)
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define PIXEL565G(v) ((((uint32_t)v >> 5) << 2) & 0xff)
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define PIXEL565B(v) (((uint32_t)v << 3) & 0xff)


public delegate void BridgeCB(BridgeMap o, uc_engine uc);
public delegate void BridgeInit(BridgeMap o, uc_engine uc, uint addr);

public enum BridgeMapType
{
	MAP_DATA,
	MAP_FUNC,
}

public unsafe struct BridgeMap
{
	public IntPtr name;
	public uint pos;
	public BridgeMapType type;
	//public BridgeInit initFn;
	//public BridgeCB fn;
	public IntPtr initFn;
	public IntPtr fn;
	public uint extraData;

    public BridgeMap(string field, int offset, BridgeMapType mapType, BridgeInit init, BridgeCB func, int extraData)
    {
		name =new IntPtr((sbyte*)arm.getBytePtr(System.Text.Encoding.Default.GetBytes(field)));
		pos = (uint)offset;
		type = mapType;
		if (init != null)
			initFn = Marshal.GetFunctionPointerForDelegate(init);
		else
			initFn = IntPtr.Zero;
		if (func != null)
			fn = Marshal.GetFunctionPointerForDelegate(func);
		else
			fn = IntPtr.Zero;
		this. extraData = (uint)extraData;
	}
}

//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define SET_RET_V(ret) { uint32_t _v = ret; uc_reg_write(uc, UC_ARM_REG_R0, &_v); }

public struct _mr_c_event_st
{
	public int code;
	public int param0;
	public int param1;
	public int param2;
	public int param3;
}

//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: Enums must be named in C#, so the following enum has been named AnonymousEnum:
public enum AnonymousEnum
{
	MR_SOUND_MIDI,
	MR_SOUND_WAV,
	MR_SOUND_MP3,
	MR_SOUND_AMR,
	MR_SOUND_PCM // 8K 16bit PCM
}

//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: Enums must be named in C#, so the following enum has been named AnonymousEnum2:
public enum AnonymousEnum2
{
	MR_DIALOG_KEY_OK, // 对话框/文本框等的"确定"键被点击(选择);
	MR_DIALOG_KEY_CANCEL // 对话框/文本框等的"取消"("返回")键被点击(选择);
}

//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: Enums must be named in C#, so the following enum has been named AnonymousEnum3:
public enum AnonymousEnum3
{
	MR_DIALOG_OK, // 对话框有"确定"键;
	MR_DIALOG_OK_CANCEL, // 对话框有"确定" "取消"键;
	MR_DIALOG_CANCEL // 对话框有"返回"键
}

/*
创建一个对话框，并返回对话框句柄。当对话框显示时，如果用户按了对话框上的某个键，系统将构造Mythroad应用消息，通过mrc_event函数传送给Mythroad应用，
消息类型为MR_DIALOG_EVENT，参数为该按键的ID。"确定"键ID为：MR_DIALOG_KEY_OK；"取消"键ID为：MR_DIALOG_KEY_CANCEL。
title [IN]对话框的标题，unicode编码，网络字节序
text [IN]对话框内容，unicode编码，网络字节序
type [IN]对话框类型：MR_DIALOG_OK MR_DIALOG_OK_CANCEL MR_DIALOG_CANCEL

Return Value 正整数 对话框句柄 MR_FAILED 失败 
*/
#if __EMSCRIPTEN__
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The following statement was not recognized, possibly due to an unrecognized macro:
EM_JS(int, js_mr_dialogCreate, (const sbyte * title, const sbyte * text, int type), {return js_dialogCreate(title, text, type);});
#endif

//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: Enums must be named in C#, so the following enum has been named AnonymousEnum4:
public enum AnonymousEnum4
{
	MR_EDIT_ANY,
	MR_EDIT_NUMERIC,
	MR_EDIT_PASSWORD
}

/*
创建一个编辑框，并返回编辑框句柄。 
title [IN]文本框的标题，unicode编码，网络字节序
text [IN]文本框内容，unicode编码，网络字节序
type [IN]见MR_EDIT_ANY;MR_EDIT_NUMERIC;MR_EDIT_PASSWORD定义
max_size [IN]最多可以输入的字符（unicode）个数，这里每一个中文、字母、数字、符号都算一个字符 
Return Value 正整数 编辑框句柄 MR_FAILED 失败 
Remarks
   编辑框用来显示并提供用户编辑文字信息。text是编辑框显示的初始内容。当编辑框显示时，
如果用户选择了编辑框上的某个键，系统将构造Mythroad应用消息，通过mrc_event函数传送给
Mythroad应用，消息类型为MR_DIALOG_EVENT，参数为该按键的ID;"确定"键ID为：MR_DIALOG_KEY_OK；
"取消"键ID为：MR_DIALOG_KEY_CANCEL。 
*/
#if __EMSCRIPTEN__
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 TODO TASK: The following statement was not recognized, possibly due to an unrecognized macro:
EM_JS(int, js_mr_editCreate, (const sbyte * title, const sbyte * text, int type, int max_size), {return js_editCreate(title, text, type, max_size);});
#endif